package cn.glutnn.dao;

import java.util.List;

import cn.glutnn.entity.Notice;
import cn.glutnn.util.JdbcUtils;

public class NoticeDao {

	public List<Notice> find(String noticeName) {
		// （完成）实现查询数据库的逻辑
		String sql = "select * from t_notice where 1=1";
		
		if (noticeName != null) {
			sql += " and name='" + noticeName + "'";
		}
		
//		if (showdate != null) {
//			sql += " and showdate='" + showdate + "'";
//		}
	
		// 3、返回结果集包装在List<Notice>
		List<Notice> list = JdbcUtils.query(sql, Notice.class);
		return list;
	}

	public boolean save(Notice notice) {
		//实现保存逻辑
		boolean isOK = JdbcUtils.save(notice);
		return isOK;
	}
	
	public boolean update(Notice notice) {
		// 实现更新逻辑
		return JdbcUtils.update(notice);
	}
	
	/**
	 * 删除逻辑
	 */
	public boolean delete(Integer id) {
		return JdbcUtils.delete(id, Notice.class);
	}

	public Notice findOne(String name) {
		Notice notice = null;
		List<Notice> list = this.find(name);
		if (list.size() == 1) {
			notice = list.get(0);
		}
		// 2-2、获取电影
		return notice;
	}

}
